package tech.konata.yukkuri.utils.resource;

import lombok.SneakyThrows;
import lombok.experimental.UtilityClass;

import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.InputStream;

@UtilityClass
public class ResourceUtil {

    public static final Image ICON = loadImageInClassPath("/icon.png");

    @SneakyThrows
    public Image loadImageInClassPath(String path) {

        try (InputStream is = ResourceUtil.class.getResourceAsStream(path)) {

            if (is == null)
                throw new IllegalArgumentException("Cannot read file '" + path + "' !");

            return ImageIO.read(is);

        }

    }

}
